#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long LL;
#define endl '\n'
const int N = 3e5 + 10;
struct node
{
    int x, y, z;
}op[N];
int b[N];
int a[N];
int n, q;


void solve() 
{
    cin >> n >> q;
    unordered_map<int, int> aper;
    for(int i = 1; i <= n; i++) cin >> b[i];
    for(int i = 1; i <= q; i++) 
    {
        cin >> op[i].x >> op[i].y >> op[i].z;
        aper[op[i].z]++;
    }
    for(int i = 1; i <= n; i++)
    {
        if(!aper.count(i)) a[i] = b[i];
        cout << a[i] << " ";
    }

}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T;
	cin >> T;
	while(T--)
	{
        solve();
	}
	return 0;
}